// 引入react
import * as React from 'react';
//导航容器
// react-navigation/native 在版本6.0中才有
import {NavigationContainer} from '@react-navigation/native';
import {connect} from 'react-redux';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import {HomeScreen} from '../pages/Home';
import Login from '../pages/Login';
// import SettingsInfoScreen from '../src/pages/Home/SettingInfos';

import store from '../store';
import {ClassessManageScreen} from '../pages/Home/SettingInfos/ClassesManage';
import {SaveClassScreen} from '../pages/Home/SettingInfos/ClassesManage/SaveClasses';
import {SetName} from '../pages/Home/SettingInfos/ClassesManage/SaveClasses/SetName';
import {SignPlanGroup} from '../pages/Home/SettingInfos/SignPlanGroup'
import {SaveSignPlanGroup} from '../pages/Home/SettingInfos/SignPlanGroup/SaveSignPlanGroup/SaveSignPlanGroup';
import {SignPeriod} from '../pages/Home/SettingInfos/SignPlanGroup/SaveSignPlanGroup/SignPeriod/SignPeriod';
import {SpecialDate} from '../pages/Home/SettingInfos/SignPlanGroup/SaveSignPlanGroup/SignPeriod/SpecialDate';
import {SignEmp} from '../pages/Home/SettingInfos/SignPlanGroup/SaveSignPlanGroup/SignEmp/SignEmp';
import {SignPlace} from '../pages/Home/SettingInfos/SignPlanGroup/SaveSignPlanGroup/signPlace/signPlace';
import AddMap from '../pages/Home/SettingInfos/SignPlanGroup/SaveSignPlanGroup/signPlace/addMap';
import {getToken} from '../utils/Auth';
import {Set_Token} from '../store/actions/user';
import {UserStatisticsDetails} from '../pages/Home/StatisticsInfos/UserStatisticsDetails';
import {MyStatistics} from '../pages/Home/StatisticsInfos/MyStatistics';
import {ReportForm} from '../pages/Home/StatisticsInfos/TeamStatistics/ReportForm';
import {ClockingDetails} from '../pages/Home/StatisticsInfos/TeamStatistics/ClockingDetails';
import {MonthStatistics} from '../pages/Home/StatisticsInfos/TeamStatistics/MonthStatistics';
import {AllUserStatistics} from '../pages/Home/StatisticsInfos/AllUserStatistics';
import {MySetting} from '../pages/Home/SettingInfos/MySetting';
import {SetPassword} from '../pages/Home/SettingInfos/MySetting/SetPassword/SetPassword';
import {SetUserName} from '../pages/Home/SettingInfos/MySetting/SetUserName/SetUserName';
import {FaceRecord} from '../pages/Home/SettingInfos/FaceRecord/FaceRecord';
import {FaceManagement} from '../pages/Home/SettingInfos/FaceManagement/FaceManagement';
import {FaceAudit} from '../pages/Home/SettingInfos/FaceManagement/FaceAudit';
import {PhotoReview} from '../pages/Home/SettingInfos/FaceManagement/PhotoReview';
import {FaceDetection} from '../pages/Home/SettingInfos/FaceRecord/FaceDetection';
import {FaceRecognitionPunch} from '../pages/Home/signHome/FaceRecognitionPunch';
import {LocationListScreen} from '../pages/Home/signHome/LocationListScreen';

const Stack = createNativeStackNavigator();

class AppNavigator extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            //isLoading: true,
            //userToken: this.props.userToken
        };
    }
    //生命周期：组件挂载后
    componentDidMount() {
        // this.time();
    }

    // time = () => {
    //     setTimeout(
    //         () => {
    //             this.setState({isLoading: false});
    //         }, 500,
    //     );
    // };

    render() {
        let token = store.getState().userReducer.token;
        console.log('查看token------------',token)
        //是否为加载页
        // if (this.state.isLoading) {
        //     return <LodingScreen/>;
        // }
        // alert("123")
        return (
            <NavigationContainer>
                <Stack.Navigator initialRouteName="home"
                                 screenOptions={({route, navigation}) => ({headerShown: false})}>
                    {token != null ?  (
                        <Stack.Group>
                            <Stack.Screen name='home' component={HomeScreen}
                                          options={{
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='ClassesManege'
                                          component={ClassessManageScreen}
                                          options={{
                                              title:'班次管理',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='SaveClass'
                                          component={SaveClassScreen}
                                          options={{
                                              title:'保存班次',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='SetName'
                                          component={SetName}
                                          options={{
                                              title:'班次名称',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='SignPlanGroup'
                                          component={SignPlanGroup}
                                          options={{
                                              title:'班次方案考勤组',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='SaveSignPlanGroup'
                                          component={SaveSignPlanGroup}
                                          options={{
                                              title:'保存班次方案考勤组',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='SignPeriod'
                                          component={SignPeriod}
                                          options={{
                                              title:'考勤日期',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='SpecialDate'
                                          component={SpecialDate}
                                          options={{
                                              title:'特殊日期',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='SignEmp'
                                          component={SignEmp}
                                          options={{
                                              title:'选择考勤员工',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='signPlace'
                                          component={SignPlace}
                                          options={{
                                              title:'打卡地点',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='addMap'
                                          component={AddMap}
                                          options={{
                                              title:'打卡地点',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='userStatisticsDetails'
                                          component={UserStatisticsDetails}
                                          options={{
                                              title:'个人月统计详情',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='reportForm'
                                          component={ReportForm}
                                          options={{
                                              title:'考勤报表',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='clockingDetails'
                                          component={ClockingDetails}
                                          options={{
                                              title:'打卡明细',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='monthStatistics'
                                          component={MonthStatistics}
                                          options={{
                                              title:'打卡明细',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='allUserStatistics'
                                          component={AllUserStatistics}
                                          options={{
                                              title:'用户统计',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='mySetting'
                                          component={MySetting}
                                          options={{
                                              title:'我的设置',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='setUserName'
                                          component={SetUserName}
                                          options={{
                                              title:'设置姓名',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='setPassword'
                                          component={SetPassword}
                                          options={{
                                              title:'修改密码',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='faceManagement'
                                          component={FaceManagement}
                                          options={{
                                              title:'人脸管理',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='faceAudit'
                                          component={FaceAudit}
                                          options={{
                                              title:'人脸管理',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='photoReview'
                                          component={PhotoReview}
                                          options={{
                                              title:'照片审核',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='faceRecord'
                                          component={FaceRecord}
                                          options={{
                                              title:'人脸录入',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='faceDetection'
                                          component={FaceDetection}
                                          options={{
                                              title:'人脸检测模块',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='faceRecognitionPunch'
                                          component={FaceRecognitionPunch}
                                          options={{
                                              title:'人脸识别打卡',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />
                            <Stack.Screen name='locationListScreen'
                                          component={LocationListScreen}
                                          options={{
                                              title:'考勤打卡地点',
                                              //动画推送方式
                                              animationTypeForReplace: 'pop',
                                              //取消动画
                                              //animation: "none"
                                          }}
                            />

                        </Stack.Group>
                    ):(
                        <Stack.Group>
                            <Stack.Screen name='login' component={Login} options={{
                                animationTypeForReplace: 'push',
                                //动画从底部到顶部
                                animation: 'slide_from_bottom',
                                title: '登陆',
                            }}/>
                        </Stack.Group>



                        )
                    }


                </Stack.Navigator>
            </NavigationContainer>
        );
    }
}

/**
 * @Description:构造connect参数方法将全局状态转变为props，使得子组件AppNavigator接收值
 * 在子组件中用this.props.userToken 访问
 * @author TangYong
 * @date 2022/5/4
 */
const stateToProps = (state) => {
    return {
        userToken: state.userReducer.token,
    };
};

export default connect(stateToProps, null)(AppNavigator);

